home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 352_01.zip / DBLIB.H < prev    next >
C/C++ Source or Header  |  1993-04-10  |  27KB  |  820 lines

  1. #ifndef DBLIB_HEADER
  2.     #define DBLIB_HEADER
  3. #include "wtwg.h"
  4. #include "string.h"
  5. #include <iostream.h>
  6. #include <alloc.h>
  7. #include <dos.h>
  8.  
  9. /* farmemcpy()
  10.  * in large models this is just memcpy
  11.  * but in small models it's movedata()
  12.  */
  13. #undef LARGE_DATA_MODEL
  14. #ifdef __LARGE__
  15.     #define LARGE_DATA_MODEL
  16. #endif
  17. #ifdef __COMPACT__
  18.     #define LARGE_DATA_MODEL
  19. #endif
  20. #ifdef __HUGE__
  21.     #define LARGE_DATA_MODEL
  22. #endif 
  23.  
  24.  
  25.  
  26.  
  27. #ifdef LARGE_DATA_MODEL
  28.     #define farmemcpy(aa,bb,cc)  memcpy (aa,bb,cc)
  29. #else
  30.  
  31.     /* model is small or medium - need a far * equivalent of
  32.      * memcpy, write, read, memcmp
  33.      */
  34.     #define farmemcpy(dest,src,num)  \
  35.     movedata (FP_SEG(src), FP_OFF(src), FP_SEG(dest), FP_OFF(dest), num )
  36.  
  37. #endif    /* memcpy */
  38.  
  39.  
  40.  
  41. // min & max. - these are undefined in TurboC++
  42. #ifndef min
  43.     #define min(x,y)   (( (x) < (y) ) ? (x) : (y))
  44. #endif
  45. #ifndef max
  46.     #define max(x,y)   (( (x) > (y) ) ? (x) : (y))
  47. #endif
  48.  
  49.  
  50.  
  51.  
  52.  
  53. /* array index routines.
  54.  *
  55.  * roll_up, roll_down
  56.  *    returns the next/prev index to an array of max items
  57.  *     arranged in a circle  0 -> 1 -> 2 -> ... -> max -> 0 etc...
  58.  * inch_up, inch_down
  59.  *    increases or decreases the index but stays within array bounds
  60.  */
  61. #define roll_up(n, max)      ( (n) == (max)-1 ? 0       : (n)+1 )
  62. #define roll_down(n, max)    ( (n) ==  0      ? (max)-1 : (n)-1 )
  63. #define inch_up(n, max)        ( (n) == (max)-1 ? (n)     : (n)+1 )
  64. #define inch_down(n, max)    ( (n) ==  0      ? 0       : (n)-1 )
  65.  
  66.  
  67.  
  68.  
  69.  
  70. // NORMALIZE macros.
  71. //    Far pointer normalization routine
  72. //        Arithmetic on far pointers only affects the offset,
  73. //        does not carry into the segment portion.
  74. //     to avoid overflow errors,
  75. //        must convert seg:off pair to place as much
  76. //         of the address as possible into the segment part.
  77. //
  78. //     NORMALIZE () - unconditionally normalize a far pointer.
  79. //      _NORMALIZE () - normalize a data pointer IF memory model requires it
  80. //
  81. //  use _NORMALIZE for pointers not explicitly declared far.
  82. //
  83. //    NOTE:  MODIFIED FOR C++  which must cast the result to the appropriate type
  84. // 
  85. #define NORMALIZE(fp, type)        \
  86.    fp = (type) MK_FP ( ( FP_SEG(fp) + (FP_OFF(fp)>>4) ),  \
  87.         ((unsigned)(FP_OFF(fp))& 0x000f) )
  88.  
  89.  
  90.  
  91.  
  92.  
  93. #ifdef  __COMPACT__
  94.     #define _NORMALIZE(fp,type)  NORMALIZE(fp,type)
  95. #endif
  96. #ifdef  __LARGE__
  97.     #define _NORMALIZE(fp,type)  NORMALIZE(fp,type)
  98. #endif
  99. #ifdef __SMALL__
  100.     #define _NORMALIZE(fp,type)
  101. #endif
  102. #ifdef __MEDIUM__
  103.     #define _NORMALIZE(fp,type)
  104. #endif
  105. #ifdef __HUGE__
  106.     #define _NORMALIZE(fp,type)
  107. #endif
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121. /* the next set of definitions allow use of Turbo C's ability to
  122.  *  generate in-line interrupts, while maintaining compatibility
  123.  *  with compilers that have an int86() function and a union REGS.
  124.  *
  125.  *  To use this technique, ALWAYS load the registers in inverse
  126.  *  alphabetical order (DX first, then CX, BX and AX last)
  127.  *  and don't try to do any complex computations in the lines
  128.  *  that access the registers.
  129.  *     WRONG, for 3 reasons:
  130.  *        _AH = 1;
  131.  *        _DX = value1 + 3*value2;    ===> TurboC uses AX
  132.  *        geninterrupt ( variable_int_number );  ditto
  133.  *    RIGHT, but useless:
  134.  *        value3 = value1 + 3*value2;
  135.  *        if ( int_number = 0x01 )
  136.  *            {
  137.  *            _DX = value3;
  138.  *            _AX = 1;
  139.  *            geninterrupt ( 0x01 );
  140.  *            }
  141.  *        else    {
  142.  *            _DX = value3;
  143.  *            _AX = 1;
  144.  *            geninterrupt ( 0x02 );
  145.  *            }
  146.  *
  147.  */
  148.     #ifndef  __TURBOC__
  149.         #define PSEUDOREGS union REGS regs;
  150.         #define _AX    regs.x.ax
  151.         #define _AL    regs.h.al
  152.         #define _AH    regs.h.ah
  153.         #define _BX    regs.x.bx
  154.         #define _BL    regs.h.bl
  155.         #define _BH    regs.h.bh
  156.         #define _CX    regs.x.cx
  157.         #define _CL    regs.h.cl
  158.         #define _CH    regs.h.ch
  159.         #define _DX    regs.x.dx
  160.         #define _DL    regs.h.dl
  161.         #define _DH    regs.h.dh
  162.         #define _FLAGS    regs.x.flags
  163.  
  164.         #define geninterrupt(intno)    int86((intno), ®s, ®s)
  165.  
  166.     #else
  167.         #define    PSEUDOREGS
  168.     #endif    /* end of redifinning pseudoregs and interrupts */
  169.  
  170.     //    generate inport and outport instructions inline
  171.     //  temp. fix pending TURBOC++ upgrade.
  172.     #ifndef outportb
  173.         #define outportb(portid, value)  __outportb__( (portid), (value) )
  174.         void     _Cdecl __outportb__(int __portid, unsigned char __value);
  175.  
  176.     #endif
  177.     #ifndef inportb
  178.         #define inportb(portid)  __inportb__( (portid) )
  179.         unsigned char    _Cdecl __inportb__(int __portid);
  180.     #endif
  181.  
  182. // wmatherr() -
  183. //        a routine to trap integer and floating point math errors.
  184. //        prevents program from crashing, which would leave system...
  185. //             in bizarre video modes, with expanded memory allocated, etc...
  186. //        SOURCE: wmatherr.cpp
  187. void wmatherr (void);
  188.  
  189.  
  190.  
  191. // STRINGPP.H - a string class for TurboC++
  192. //
  193. // D Blum 8/90 
  194. //
  195.  
  196.  
  197. class String {
  198.     public:
  199.             static     char caseSens;        // default = OFF  any NONZERO is ON
  200.     private:
  201.             int    n;            // strlen = numbytes not counting \0
  202.             char *s;        // the string.
  203.             void construct ( char *p );    // local utility for construction
  204.             void destruct ( );            // local utility for destruction
  205.                                         // source for both: STRPP.CPP
  206.             // Utility functions called by functions in String::
  207.             //    the utilities include copy, comparison, scanning, allocation
  208.             //                                                // source files:
  209.             static int cmp (char *a, char *b);                // STRPPCMP.CPP
  210.             static int memcmp (char *a, char *b, int nb);    // STRPPMCP.CPP
  211.             static int chrcmp ( char a, char b );            // STRPPCHC.CPP
  212.             static int findstr ( char *a, int na, char *b );// STRPPFNS.CPP    
  213.             static int findchr ( char *a, int na, char c );    // STRPPFNC.CPP
  214.             void       strpad ( );                            // STRPPPAD.CPP
  215.             void          slide ( int start, int stop );        // STRPPSLD.CPP 
  216.     public: 
  217.             // Constructors: make String from a String, a char *ptr, or a char
  218.             //                also can make fixed length strings.
  219.                 String()    { n=0; s=NULL;};
  220.                 String(int);                    // make a fixed len String 
  221.                                                 // init to all spaces.
  222.                                                 // source: STRPPFIX.CPP
  223.                 String ( char *ptr ){n = strlen (ptr); construct (ptr); };        
  224.                 String ( String& str ){ n= str.n; construct ( str.s ); };
  225.             // Copy constructor utility.
  226.                 private: void copy( int l, char *p );    // source: STRPP.CPP
  227.             public:
  228.                 void    assign ( char *data );    // assign ownership of data
  229.                                                 // data MUST have been malloc'd
  230.                                                 // and will be free'd by String
  231.                                                 //        BE CAREFULL !!!!!
  232.                                                 // STRPPASN.CPP
  233.                 String& operator=(String& source)        
  234.                     {
  235.                     copy ( source.n, source.s );
  236.                     return *this;
  237.                     };            // end assignemt operator
  238.                 String& operator=(char *ptr)
  239.                     {
  240.                     copy ( strlen(ptr), ptr );
  241.                     return *this;
  242.                     };
  243.                 String& operator= (char c)
  244.                     {
  245.                     copy ( 1, &c );
  246.                     return *this;
  247.                     };
  248.             // Destructor
  249.                 ~String ( ) {destruct();};        // source: STRPP.CPP
  250.                 
  251.             // comparison operators.
  252.             
  253.             friend int operator==(String& a, String &b)
  254.                 {return (String::cmp (a.s, b.s)==0);};
  255.             friend int operator>=(String& a, String &b)
  256.                 {return (String::cmp (a.s, b.s)>=0);};    
  257.             friend int operator<=(String& a, String &b)
  258.                 {return (String::cmp (a.s, b.s)<=0);};    
  259.             friend int operator>(String& a, String &b)
  260.                 {return (String::cmp (a.s, b.s)>0);};    
  261.             friend int operator<(String& a, String &b)
  262.                 {return (String::cmp (a.s, b.s)<0);};    
  263.             friend int operator==(char *a, String &b)
  264.                 {return (String::cmp (a, b.s)==0);};
  265.             friend int operator>=(char *a, String &b)
  266.                 {return (String::cmp (a, b.s)>=0);};    
  267.             friend int operator<=(char *a, String &b)
  268.                 {return (String::cmp (a, b.s)<=0);};    
  269.             friend int operator>(char *a, String &b)
  270.                 {return (String::cmp (a, b.s)>0);};    
  271.             friend int operator<(char *a, String &b)
  272.                 {return (String::cmp (a, b.s)<0);};    
  273.             friend int operator==(String& a, char *b)
  274.                 {return (String::cmp (a.s, b)==0);};
  275.             friend int operator>=(String& a, char *b)
  276.                 {return (String::cmp (a.s, b)>=0);};    
  277.             friend int operator<=(String& a, char *b)
  278.                 {return (String::cmp (a.s, b)<=0);};    
  279.             friend int operator>(String& a, char *b)
  280.                 {return (String::cmp (a.s, b)>0);};    
  281.             friend int operator<(String& a, char *b)
  282.                 {return (String::cmp (a.s, b)<0);};    
  283.                 
  284.                 
  285.         // CONCATENATION - 
  286.         //        two ways:  += replace old string. 
  287.         //                    + allocates new string intermediate.
  288.         //      source: STRPPCAT.CPP
  289.         //
  290.         friend String& operator+=(String& a, String& b);
  291.         friend String& operator+=(String& a, char *b);
  292.         friend String  operator+(String& a, String& b);
  293.         friend String  operator+(String& a, char *b);
  294.         friend String  operator+(char *a, String& b);
  295.         
  296.         // STREAM IO
  297.         friend ostream& operator<<(ostream& os, String& a)
  298.             { return os<<a.s; };
  299.         friend ostream& operator<<(ostream& os, String* a)
  300.             { return os<<a->s; };
  301.                 
  302.         // EXTERNAL ACCESS        casts & subscripts
  303.         // cast String to char* for times when you need a C string ptr.
  304.         // (this lets you to use Strings as parms in C funcs that need char* )
  305.         //            ex:  String myFile="prog.cpp";    fopen (myFile, "r");
  306.         //
  307.         operator char* () {return s;};        
  308.         
  309.         // subscript a String just like a C string ptr
  310.         char       operator [](int i) {return s[i];};    
  311.         
  312.         // len() get lenght of String.
  313.         int     len()  {return n;};
  314.                 
  315.         // set character at position i to value c.
  316.         //         NOTE:     no bounds checking - that's your job. 
  317.         //                Also, DONT set contents to \0 ie: myString.set (3, 0);
  318.         void set( int i, char c ) { s[i]=c; };
  319.             
  320.         // resetLen()
  321.         //    recalculate the length of the String.
  322.         //    used if a non-String func does something to shorten contents.
  323.         //
  324.         void resetLen()  { n=strlen(s); if (n==0) destruct(); };
  325.         
  326.         
  327.         // SUBSTRING()
  328.         //         creates a substring from position start for length len.
  329.         //         if len not specified or less than 0, goes to end of string.
  330.         //        if len extends beyond end of 'this' String, pads result with ' '
  331.         //         NOTE: 1) creates a new string, which must be explicitly deleted.
  332.         //              2) returns a pointer to the created String
  333.         //              3) obeys String::caseSens
  334.         //    
  335.         //                                            source: STRPPSUB.CPP
  336.         String *substring(int start, int len=0);
  337.         String *substr   (int start, int len=0) {return substring(start,len);};
  338.             
  339.             
  340.         // INSERT  insert one string into another.
  341.         // insert string ins into current string at position pos.
  342.         // alters the existing string.
  343.         //                                            source: STRPPINS.CPP
  344.         String&  insert ( char *ins, int pos );
  345.         String&  insert ( String& ins, int pos ) {return insert(ins.s,pos);};
  346.             
  347.             
  348.         // CUT  remove part of a string.
  349.         //        removes section of string between positions specified.
  350.         //            (between is inclusive)
  351.         //        Changes original string.
  352.         //        If values provided are out of range, 
  353.         //            string is replaced by an error message.
  354.         //        Default for second value is cut to end of string.
  355.         //        Example:
  356.         //        input string:    abcdefghi0
  357.         //            positions:   0123456789        n =9 letters in string.
  358.         //             cut ( 2, 5 ):abghi0    
  359.         //                    position 6 moved right to position 3
  360.         //            cut ( 2 ):   ab0            cuts to end of string.
  361.         //                                            source: STRPPCUT.CPP
  362.         String& cut ( int start, int stop= -1 );
  363.             
  364.             
  365.         // String::find() searches for a substring within target string.
  366.         //                similar to ANSI C functions strchr(), strstr() 
  367.         //                but: obeys String::caseSens rule for case sensitive 
  368.         //                RETURNS: offset into 'this' String of first occurance.
  369.         //                         -1 if not found. 
  370.         //
  371.         // example: String s1="Hello, there";
  372.         //            s1.find("there")  ----> returns 7 = offset of there.
  373.         //            s1.findAny("sample")  ----> returns 2 = position of 'l'
  374.         //    source: STRPPFNS.CPP and STRPPFNC.CPP
  375.         //
  376.         int find ( String& a ) {return String::findstr(s,n,a.s);};
  377.         int find ( char   *a ) {return String::findstr(s,n,a  );};
  378.         int find ( char    c ) {return String::findchr(s,n,c  );};
  379.         
  380.         
  381.         
  382.         // findAny()  - finds first occurance of any char within 'this' String.
  383.         //                similar to ANSI C strpbrk() 
  384.         //                but: obeys String::caseSens rule for case sensitive 
  385.         //                RETURNS: offset into 'this' String of first occurance.
  386.         //                         -1 if not found. 
  387.         //                                             source: STRPPFNA.CPP
  388.         int findAny ( char *a );    
  389.         int findAny ( String& a ) {return String::findAny(a.s);};    
  390.         
  391.         // findNot()  - finds first char which is not in the param string.
  392.         //                 functions similar to findAny()
  393.         //                RETURNS: index for first char not in param string.
  394.         //                         -1 if all chars in param are also in 'this'
  395.         //    
  396.         //                                            source: STRPPFNT.CPP
  397.         int findNot ( char * );
  398.         int findNot ( String& a)    {return String::findNot(a.s);};
  399.             
  400.             
  401.             
  402.         
  403.         // String::tokenize()  parse original string into tokens.
  404.         //        RETURNS: ptr to newly constructed String.            
  405.         //            
  406.         //        NOTE: caller has to delete each returned string
  407.         //                          or they will accumulate on the heap.
  408.         //
  409.         //        the returned string contains chars in between the tokens
  410.         //        tokenize progressively decimates 'this' down to a \0.
  411.         //
  412.         //        example:
  413.         //        String  x="a1+b2-c3";    String *y;
  414.         //                y = x.tokenize("+-");    Now x="b-3", y="a1"
  415.         //                delete y;
  416.         //                y = x.tokenize("+-");    Now x="3";   y="b2"
  417.         //                delete y;
  418.         //                y = x.tokenize("+-");    Now x=NULL,  y="c3"
  419.         //                delete y;
  420.         //
  421.         //        if no tokens are found, the entire string is returned  
  422.         //            and 'this' is decimated.            
  423.         //
  424.         //                                            source: STRPPTOK.CPP
  425.         //
  426.         String *tokenize ( char *tok );
  427.         String *tokenize ( String &Stok )  { return tokenize (Stok.s); };
  428.  
  429.         // case conversion 
  430.         //        source: STRPPTOU.CPP and STRPPTOL.CPP
  431.         void toUpper();
  432.         void toLower();
  433.             
  434.         
  435.         // squeeze()  
  436.         //        - the characters provided are squeeze'd from 'this' String
  437.         //        The resulting string may be shorter.
  438.         //        Useful for removing all whitespace, carriage returns, etc...
  439.         //            (default is remove whitespace).
  440.         //
  441.         //                                        source: STRPPSQZ.CPP
  442.         String& squeeze ( char* =" \r\n\t");    
  443.         String& squeeze ( String& a ) { return squeeze (a.s); };    
  444.             
  445.         // noExtra()
  446.         //        You specify a list of charaters to squeeze out (target chars).
  447.         //            target defaults to whitespace.
  448.         //        any 'extra' target chars from the String provided are removed.
  449.         //        characters are extra if they immediately follow another target.
  450.         //            ie: a consecutive run of target chars is shortenned to 1.
  451.         //        first char of each run is replaced by first char of target.
  452.         //        obeys String::caseSens for identifying target chars.
  453.         //
  454.         //        Similar to squeeze() but not as drastic.
  455.         //            use to simplify whitespace to single spaces only
  456.         //    
  457.         //        example:  String too_many_vowels = "Wear green paint today";
  458.         //                  String vowels = "aeiouy"
  459.         //                  too_many_vowels.noExtra(vowels);
  460.         //                    result is "War gran pant tada"
  461.         //        example:  String spacey ="Lots    \nof\t\r \nspace";    
  462.         //                  spacey.noExtra() becomes: "Lots of space";
  463.         //                                        source: STRPPNOX.CPP
  464.         String& noExtra ( char* =" \r\n\t");
  465.         String& noExtra ( String& a) { return noExtra (a.s);};
  466.         
  467.         
  468.         // trim()
  469.         //        trailing chars of 'this' are removed if found in given string
  470.         //                                        source: STRPPTRM.CPP
  471.         String& trim ( char* = " \r\n\t" );
  472.         String& trim (String& a ) { return trim (a.s); };
  473.             
  474.             
  475.         // translate()
  476.         //        characters in String found in first parm 
  477.         //        are changed to corresponding character in second parm.
  478.         //        example: String X = "12345";  
  479.         //                 X.translate ( "1234567890", "abcdefghij" );
  480.         //                 X becomes "abcde"
  481.         //                                        source: STRPPTRN.CPP
  482.         String& translate ( char *first, char *second );
  483.             
  484.         // replace()
  485.         //     replace all occurences of *original with *replacement.
  486.         //     obeys String::caseSens rule for finding original.
  487.         //    original and replacement don't have to be same lengths.
  488.         //    example: String test = "No I do not know if Nolan noticed";
  489.         //             test.replace ("no", "yes");
  490.         //            result is "yes I do yest kyes if yeslan yesticed"
  491.         //                                        source: STRPPREP.CPP
  492.         String& replace ( char *, char * );
  493.         String& replace ( String& o, String& r ) {return replace(o.s,r.s);};
  494.         String& replace ( char   *o, String& r ) {return replace(o  ,r.s);};
  495.         String& replace ( String& o, char   *r ) {return replace(o.s,r  );};
  496.         
  497.             
  498.                     // end definition of class String
  499.         };        
  500.             
  501. //---------------------------------------------------------------------------
  502.  
  503.  
  504. // make_fullfilename ()
  505. //        routine to concatenate a directory name and a file name
  506. //        PARMS:  traditional C style ptrs to char strings
  507. //                specifying directory (may be "C:\\path", "C:", "C:\\path\\" etc
  508. //                and filename (may be up to 8+1+3+1 bytes: name.ext or just name)
  509. //                and ( optional ) extension which may or may not incl. the "."
  510. //
  511. //        RETURNS a new String object (which must explicitly be deleted)
  512. //        example:
  513. //        String  *fullname = make_fullfilename ("C:\\mydir", "name.ext");
  514. //                fopen ( (char*)fullname, "rt" );
  515. //                delete fullname;
  516. //            or: *fullname = make_fullfilename ( NULL, "name.ex1", ".ex2" );
  517. //                    (above returns "name.ex2")
  518.  
  519. //        SOURCE: FULLFLNM.CPP
  520. String *make_fullfilename ( char *dir, char *fn, char *ext=NULL ); 
  521.  
  522.  
  523.  
  524.  
  525. // filesize()
  526. //        get and return filesize.
  527. //        returns -1 if file not found.
  528. //                                        source: FILESIZE.CPP
  529. long filesize ( char *filename );
  530.  
  531.  
  532. // readASCIIfile ()  writeASCIIfile ()  editASCIIfile ()
  533. //    
  534. //        readASCIIfile allocates a buffer and reads an ASCII file (text mode)
  535. //        the buffer is allocated based on the size of the ASCII file.
  536. //        extra bytes of padding may be specified, and a maximimum size can be set
  537. //        PARMS:    char *dir, char *fn, char *ext - as used by make_fullfilename()
  538. //                int pad = number of extra bytes to add to the end of the buffer
  539. //                            (so you can add more to the file later)
  540. //                NOTE: the buffer is NEVER longer than 32000 bytes
  541. //                        defined in RD_ASCII_MAXBUFFER
  542. //        RETURNS: char *buffer - ptr to the buffer holding the file's contents.
  543. //                                must be freed later.
  544. //                                IF FILE did not exist, buffer[0] = 0.
  545. //
  546. //    writeASCIIfile()
  547. //        this routine writes a buffer to the named ASCII file.
  548. //        
  549. // editASCIIfile ()
  550. //        reads in specified file, allows user to change contents, rewrites
  551. //
  552. //                                                            TEXTFILE.CPP
  553. #define RD_ASCII_MAX_BUFFER  32000
  554. void writeASCIIfile(char *dir, char *fn, char *ext, char *buffer);
  555. char *readASCIIfile(char *dir, char *fn, char *ext, size_t pad=0);
  556. void editASCIIfile ( char *title, char *dir, char *fn, char *ext, int pad=25 );
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564. // argscan() and ARGTBL
  565. //        unified approach to command-line parms.
  566. //        ARGTBL: NULL-terminated list of strings to match and addresses of data
  567. //                                also max length of string (incl term. 0)
  568. //                                if len==1, data is treated like single char.
  569. //                                if len==0, data value is converted to int.
  570. //        argscan () - interpret argc/argv according to argtbl
  571. //                RETURNS:  number of unmatched args.
  572. //                MODIFIES: argv points to list of unmatched args, terminated by 0
  573. //                    (array of ptrs to strings, with NULL terminator.)
  574. //                    return value of 0 means all args were matched.
  575. //                NOTE that argv[0] was program name, becomes 1st unmatched arg.
  576. //                
  577. //        example entries: invoke program.exe  -A- -c23 name=GEORGE 
  578. //                    char name[10], switchA='+', int count=1;  ...defaults
  579. //                    ARGTBL args[]= {"name=",name, sizeof(name),
  580. //                                    "-A",   switchA, sizeof(switchA),
  581. //                                    "-C",   count, 0 }; 
  582. //        NOTE: uses case-insenstive match.
  583. //        
  584. //                                    source: ARGSCAN.CPP
  585. typedef struct st_argtbl
  586.     {
  587.     char *arg_id;
  588.     void *arg_ptr;
  589.     int   arg_len;
  590.     }
  591.     ARGTBL;
  592.  
  593. int argscan ( int argc, char **argv, ARGTBL *argtbl );
  594.     
  595.  
  596.  
  597.  
  598.  
  599. //FEOW.C - function to ask user "File Exists, Over Write?"
  600. //        PARAMS: char dir = directory name.         MUST HAVE strlen(dir) < MAXDIR
  601. //                char fn[8+1=3+1] = file name
  602. //
  603. //        User gets chance to change file name, so provide storage for 8+1+3+1
  604. //        RETURNS: ENTER or ESCAPE
  605. //                                            source: FEOW.CPP
  606. int fe_ow ( char *dir, char *fn );        
  607.     
  608.     
  609.     
  610.     
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618. //  LINKLIST.- a base class for including linked lists into other classes
  619. //                for TurboC++
  620. //
  621. //        This is NOT a container class. 
  622. //        Each object in this class is one node of a linked list,
  623. //            so to create a linked list of a derived class, 
  624. //            the derived class has to have one base-node for the whole class
  625. //                                        and as many nodes as there are objects.
  626. //
  627. //        example:(note macro creates 'node' and 'base'.):
  628. //        class SampleClass {
  629. //                InheritLinkClass(SampleClass)        <<<< NOTE no semicolon
  630. //                public:
  631. //                SampleClass()  : node(base,this) { ...constructor stuff... };
  632. //                ~SampleClass()                      {   node.unLink(); };            
  633. //                };
  634. //
  635. //
  636. //    DBlum 8/90
  637.  
  638.  
  639. class  LinkClass {
  640.     private:  LinkClass *nx, *pv; void *dt;
  641.               void initBase ();
  642.     public:         
  643.         // Constructors: one for empty nodes, one for nodes linked to base.
  644.         LinkClass()             { nx=pv=this; dt=NULL;}; 
  645.         LinkClass(LinkClass& base, void *data);
  646.         // Destructors: none. assumes derived classes removes nodes from list
  647.         int  isEmpty ();
  648.         void insertAbove ( LinkClass & );    // mv 'this' above specified obj
  649.         void insertBelow ( LinkClass & );    // mv 'this' below
  650.         void * next ()     {return  nx-> dt;};    
  651.         void * prev ()    {return  pv-> dt;};
  652.         void unLink (); 
  653.         void data ( void *new_this )    { dt = new_this; };
  654.         };
  655.         
  656.     // InheritLinkClass() macro allows correct typecasting of return values
  657.     //     from the calls to first() last() next() and prev().
  658.     //
  659.  
  660.     #define InheritLinkClass(typecast)    \
  661.     private:   static     LinkClass base;            /* one per class */    \
  662.                         LinkClass node;            /* one per object*/    \
  663.     public:                                                        \
  664.     typecast*     first( ) { return (typecast*) base.next(); };    \
  665.     typecast*     last ( ) { return (typecast*) base.prev(); };    \
  666.     typecast*     next ( ) { return (typecast*) node.next(); };    \
  667.     typecast*     prev ( ) { return (typecast*) node.prev(); };    \
  668.     static int     isEmpty() { return base.isEmpty(); };            \
  669.     void         moveAbove(typecast & target )         \
  670.                     {                                \
  671.                     node.unLink();                \
  672.                     node.insertAbove (target.node);    \
  673.                     };                                \
  674.     void         moveBelow(typecast & target )         \
  675.                     {                                 \
  676.                     node.unLink();                 \
  677.                     node.insertBelow (target.node);    \
  678.                     };                                
  679.     // end of InheritLinkClass() macro.
  680.  
  681.  
  682.  
  683.  
  684. // Vlist - a general array of ptrs. 
  685. //         works best as an array of ptrs to char*
  686. //         the Vlist makes its own copy of the indicated string
  687. //            when the list is deleted.
  688. //        So you can add static strings, consts, items on local heap, etc...
  689. //        ie: Vlist is NOT a container class 
  690. //            in the sense of smalltalk or like the TurboC++ classlib.
  691. //                                
  692.  
  693. class Vlist {
  694.     private:
  695.         int max;            // max number of entries without reallocating.
  696.         int n;                // number actually in list, not counting NULL @end
  697.         void **list;        // ptr to array of ptrs
  698.         virtual int compare ( void*, int );
  699.                     // compare as strings or FixedLen structures.
  700.         virtual void copy ( void* );        // add copy of element.
  701.                                             // doesn't check size of list.
  702.     public:
  703.         Vlist ();            // constructors. No parms = list of strings
  704.         void Vlist::clear (void);            // remove all entries.        
  705.         ~Vlist ()  {this->clear();};
  706.         
  707.         Vlist (Vlist&);                        // VLISTEQ.CPP
  708.         Vlist& operator=(Vlist&);            // VLISTEQ.CPP
  709.  
  710.         int count (void)    {return n;};
  711.         int isEmpty (void)    {return (n==0);};
  712.  
  713.         
  714.         void push ( void* );            // add item to list.
  715.                                         
  716.         void push ( Vlist& );            // add one list to another. VLISTEQ.CPP        
  717.                                                             
  718.         void pop ( void );                // remove most recent item from list                        
  719.                                         
  720.         void Remove ( int );            // remove specific item from list
  721.                                         // parm is item to match to.
  722.                                         // NOTE remove() is a TurboC macro
  723.                                         //    so can't use it as a func. name.
  724.                                                                 
  725.         operator char **()     { return (char **)list;    };                                    
  726.         char *     operator[](int i) { return (char*)( list[i] );};                        // index list gives items stored.
  727.                                         // ie: Vlist vl;
  728.                                         //     vl.push ("String a");
  729.                                         //       vl.push ("String b");
  730.                                         //     for (int n=0; vl[n] !=NULL; ++n)
  731.                                         //            ... iterate thru list.
  732.                                         //            vl[1] = "String b"
  733.         
  734.         int match ( void * );            // find item in given Vlist
  735.                                         // returns offset number 
  736.                                         // returns n ( [] to NULL ) if not found
  737.                                         // VLMATCH.CPP
  738.         
  739.         
  740.         
  741.         };        // end of definition of class Vlist.
  742.         
  743.         
  744. // VlistParseString () -  parse a String into a Vlist.
  745. //        params: Vlist& v is list to hold output (=parsed string)
  746. //                char* s is input String to parse ( or may use String& s )
  747. //                sepchars are separators to use in parsing.
  748. //                NOTE: uses Vlist, String::tokenize() functions.
  749. //        returns: number of token words found.    VLPARSES.CPP
  750. int VlistParseString ( Vlist& v, char *s, char *sepchars =",;\n\r" );         
  751.         
  752.         
  753.  
  754. //    WILDFILE - functions for expanding DOS wildcard filenames
  755. //    wildfile - pass it a filename (may include drive and path), and attr
  756. //                (see findnext/findfirst in TurboC for meanings of attr)
  757. //             - return is a ptr to a new Vlist of all matching files.
  758. //                    (the new Vlist must be explicitly free'd)
  759. //
  760. //    wildfile_pick - params are same as for wildfile().
  761. //                constructs a Vlist, shows contents to user (calls wpicklist() )
  762. //                user selects a file, 
  763. //                caller's string area for filename is overwritten
  764. //                with the selected filename ( max len=8+1+3+1 )
  765. //                or with \0 if no matching files or user hits ESCAPE.
  766. //                (The Vlist is free'd);
  767. //
  768. void  wildfile_pick (char *spec, int attr =0);
  769. Vlist  *wildfile     (char *spec, int attr =0);
  770.  
  771.  
  772.  
  773.  
  774.  
  775. /* wfvfile ()    
  776.  *        WFORM entry validation routine for file names.
  777.  *        uses data in form as a string for file specification "*.*" or similar
  778.  *        if wildcards are present, presents user with list of files.
  779.  *        if no wildcards, makes sure file exists, and gives 'not found' message
  780.  *        PARAMETERS & RETURN VALUES: as defined for form editing routines.
  781.  *        NOTE: the data item named MUST BE AT LEAST 13 bytes, long enough to hold
  782.  *                "filename.ext"+terminal 0 = 8+1+3+1.
  783.  *     SOURCE WFVFILE.C
  784.  */
  785. int wfvfile ( WFORM *form, char *buffer );
  786.  
  787.  
  788. /* macro for easy form creation for file items.
  789.  */
  790. #define  WFORMENTRY_FL(xx) #xx ": ",  xx, NULL, "%s", wfvfile, 13, 0
  791.  
  792.  
  793. // wfvpath()
  794. //    form entry validation to validate DOS paths
  795. //    valid entries are: NULL, path\ or c:\path, etc...
  796. //    path is checked to make sure it exists and is not empty.
  797. //                                        source: WFVPATH.CPP
  798. int wfvpath (WFORM *fm, char *buf);
  799.  
  800. /* macro for easy form creation
  801.  */
  802. #define  WFORMENTRY_PT(xx) #xx ": ",  xx, NULL, "%s", wfvpath, sizeof(xx), 0
  803.  
  804.  
  805. // validate_path()
  806. //    PARAM: char *path = string giving (optional) drive: and path to check.
  807. //                        max length of string is MAXDRIVE+MAXDIR (see dir.h)
  808. //            path may or may not end in \
  809. //    RETURN  0 if path exists
  810. //           -1 if path doesn't exist.
  811. //    NOTE:     NULL is considered to be a valid path (current directory)
  812. //                        
  813. //                                        source: VLDTPATH.CPP
  814. int validate_path ( char *path );        
  815.     
  816.  
  817.  
  818.  
  819.  
  820. #endif        // end of DBLIB.H for TurboC++